home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / Hello / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  8.0 KB  |  281 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                HelloFrm.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Hello.hpp"
  11.  
  12. #ifndef FRAME_H
  13. #include "Frame.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef COMMANDS_H
  21. #include "Commands.h"
  22. #endif
  23.  
  24. #ifndef CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. // ----- Framework Layer -----
  29.  
  30. #ifndef FWCONTXT_H
  31. #include "FWContxt.h"
  32. #endif
  33.  
  34. #ifndef FWUTIL_H
  35. #include "FWUtil.h"
  36. #endif
  37.  
  38. #ifndef FWPRESEN_H
  39. #include "FWPresen.h"
  40. #endif
  41.  
  42. #ifndef FWSELECT_H
  43. #include "FWSelect.h"
  44. #endif
  45.  
  46. #ifndef FWGROWBX_H
  47. #include "FWGrowBx.h"
  48. #endif
  49.  
  50. #ifndef FWSCLBAR_H
  51. #include "FWSclBar.h"
  52. #endif
  53.  
  54. // ----- OS Layer -----
  55.  
  56. #ifndef FWMENU_H
  57. #include "FWMenu.h"
  58. #endif
  59.  
  60. #ifndef FWEVENT_H
  61. #include "FWEvent.h"
  62. #endif
  63.  
  64. #ifndef FWALERT_H
  65. #include "FWAlert.h"
  66. #endif
  67.  
  68. // ----- Graphic Includes -----
  69.  
  70. #ifndef FWRECT_H
  71. #include "FWRect.h"
  72. #endif
  73.  
  74. #ifndef FWTXTBOX_H
  75. #include "FWTxtBox.h"
  76. #endif
  77.  
  78. #ifndef FWRECSHP_H
  79. #include "FWRecShp.h"
  80. #endif
  81.  
  82. // ----- OpenDoc Includes -----
  83.  
  84. #ifndef SOM_Module_OpenDoc_StdProps_defined
  85. #include <StdProps.xh>
  86. #endif
  87.  
  88. #ifndef SOM_ODDragItemIterator_xh
  89. #include <DgItmIt.xh>
  90. #endif
  91.  
  92. //========================================================================================
  93. // Runtime Information
  94. //========================================================================================
  95.  
  96. #ifdef FW_BUILD_MAC
  97. #pragma segment odfhello
  98. #endif
  99.  
  100. FW_DEFINE_AUTO(CHelloFrame)
  101.  
  102. //========================================================================================
  103. // CHelloFrame class
  104. //========================================================================================
  105.  
  106. //----------------------------------------------------------------------------------------
  107. // CHelloFrame constructor
  108. //----------------------------------------------------------------------------------------
  109. CHelloFrame::CHelloFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CHelloContent* content) :
  110.     FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
  111.     FW_MDraggableFrame(ev, this),
  112.     FW_MDroppableFrame(ev, this),    
  113.     fHelloContent(content)
  114. {
  115. }
  116.  
  117. //----------------------------------------------------------------------------------------
  118. // CHelloFrame destructor
  119. //----------------------------------------------------------------------------------------
  120.  
  121. CHelloFrame::~CHelloFrame()
  122. {
  123. }
  124.  
  125. //----------------------------------------------------------------------------------------
  126. //    CHelloFrame::CanAcceptDrop
  127. //----------------------------------------------------------------------------------------
  128.  
  129. ODDragResult CHelloFrame::CanAcceptDrop(Environment* ev, ODDragItemIterator* dragInfo)
  130. {
  131.     ODDragResult acceptDrop = FW_MDroppableFrame::CanAcceptDrop(ev, dragInfo);
  132.  
  133.     // ----- Test for 'TEXT' also -----
  134. #ifdef FW_BUILD_MAC
  135.     if (!acceptDrop)
  136.     {
  137.         for (ODStorageUnit* dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
  138.             if (dragSU->Exists(ev, kODPropContents, FW_CPart::gMacTEXTDataType, 0))    // 'TEXT' on Scrap
  139.                 return TRUE;
  140.     }
  141. #endif
  142.  
  143.     return acceptDrop;
  144. }
  145.  
  146. //----------------------------------------------------------------------------------------
  147. //    CHelloFrame::DoMouseDown
  148. //----------------------------------------------------------------------------------------
  149.  
  150. FW_Boolean CHelloFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  151. {
  152.     FW_Boolean result = FALSE;
  153.  
  154.     if (GetPresentation(ev)->GetSelection(ev)->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE))
  155.     {
  156.         result = this->Drag(ev, theMouseEvent);
  157.     }
  158.  
  159.     return result;
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. // CHelloFrame::DoAdjustMenus
  164. //----------------------------------------------------------------------------------------
  165.  
  166. FW_Boolean CHelloFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  167.                                       FW_Boolean hasMenuFocus,
  168.                                       FW_Boolean isRoot)    // Override
  169. {
  170.     if (hasMenuFocus)
  171.     {
  172.         //---- Set up the Edit menu items ----
  173. #ifdef FW_BUILD_MAC
  174.         menuBar->EnableCommand(ev, kODCommandPaste, HasPropertyOnClipboard(ev, kODPropContents, FW_CPart::gMacTEXTDataType));
  175. #endif
  176.     }
  177.     
  178.     return FALSE;
  179. }
  180.  
  181. //----------------------------------------------------------------------------------------
  182. // CHelloFrame::Draw
  183. //----------------------------------------------------------------------------------------
  184.  
  185. void CHelloFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  186. {
  187.     FW_CViewContext fc(ev, this, odFacet, invalidShape);
  188.     FW_CRect invalidRect;
  189.     fc.GetClipRect(invalidRect);
  190.  
  191.     FW_CRectShape::RenderRect(fc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  192.  
  193.     FW_CRect helloRect = GetBounds(ev);
  194.  
  195.     FW_CRectShape::RenderRect(fc, helloRect, FW_kFrame, FW_CInk(FW_kRGBBlack));
  196.  
  197.     // If this is a root part, draw the text centered horizontally and vertically.
  198.     // If it's an embedded part, center the text horizontally, with word wrap and clipping.
  199.     FW_TextBoxOptions options = FW_kTextBoxJustifyHCenter | FW_kTextBoxJustifyVCenter;
  200.     if (!fHelloContent->IsTextCentered())
  201.     {
  202.         options |= FW_kTextBoxWordWrap;
  203.         options |= FW_kTextBoxClipToBox;
  204.     }
  205.     FW_CTextBoxShape::RenderTextBox(
  206.         fc,
  207.         fHelloContent->GetTextData(),
  208.         helloRect,
  209.         FW_CFont(FW_kSystemFont, FW_kPlain, FW_IntToFixed(12)),
  210.         options);
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214. // CHelloFrame::FrameShapeChanged
  215. //----------------------------------------------------------------------------------------
  216. // By default a FW_CFrame view is not refreshed entirely when resized.
  217. // You must decide if your content's appearance depends on the frame's size.
  218. // If it doesn't you don't need to override FrameShapeChanged().
  219. // Here we must redraw the whole frame everytime because the text is centered.
  220.  
  221. void CHelloFrame::FrameShapeChanged(Environment* ev)
  222. {
  223.     FW_CFrame::FrameShapeChanged(ev);
  224.     
  225.     this->Invalidate(ev);
  226. }
  227.  
  228. //----------------------------------------------------------------------------------------
  229. //    CHelloFrame::NewClipboardCommand
  230. //----------------------------------------------------------------------------------------
  231.  
  232. FW_CClipboardCommand* CHelloFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  233. {
  234.     return FW_NEW(CHelloEditCommand, (ev, commandID, fHelloContent, this));
  235. }
  236.  
  237. //----------------------------------------------------------------------------------------
  238. //    CHelloFrame::NewDragCommand
  239. //----------------------------------------------------------------------------------------
  240.  
  241. FW_CDragCommand* CHelloFrame::NewDragCommand(Environment *ev, 
  242.                                             FW_CFrame* theFrame,
  243.                                             const FW_CMouseEvent& theMouseEvent)
  244. {
  245.     return FW_NEW(CHelloDragCommand, (ev, fHelloContent, theFrame));
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    CHelloFrame::NewDropCommand
  250. //----------------------------------------------------------------------------------------
  251.  
  252. FW_CDropCommand* CHelloFrame::NewDropCommand(Environment* ev,
  253.                                              FW_CFrame* frame,
  254.                                              ODDragItemIterator* dropInfo, 
  255.                                              ODFacet* odFacet, 
  256.                                              const FW_CPoint& dropPoint)
  257. {
  258.     return FW_NEW(CHelloDropCommand, (ev, fHelloContent, this, dropInfo, odFacet, dropPoint));
  259. }
  260.  
  261. //----------------------------------------------------------------------------------------
  262. //     CHelloFrame::CreateSubViews
  263. //----------------------------------------------------------------------------------------
  264.  
  265. void CHelloFrame::CreateSubViews(Environment* ev)
  266. {        
  267.     // Create a GrowBox only in root frame
  268.     // Note: you do not need CreateSubViews if the views are defined in resources.
  269.     //        See the Container or Form samples.
  270.     
  271.     if (this->IsRoot(ev)) 
  272.     {
  273.         FW_CRect frameRect = GetBounds(ev);  
  274.         FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  275.         frameRect.right -= sbSize.x;
  276.         frameRect.bottom -= sbSize.y;
  277.         
  278.         FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, frameRect.BotRight());
  279.     }
  280. }
  281.